<template>
  <div>
    <!-- 按钮 -->
     <div class="btns">
        <!-- 数据检索组建 -->
      <el-row :gutter="20">
        <el-col :span="18">
          <el-input placeholder="请输入内容" v-model="param.name" clearable @clear="getUserList">
            <el-button slot="append" icon="el-icon-search" @click="loadGreenHouse"></el-button>
          </el-input>
        </el-col>
        <el-col :span="5">
          <el-button type="primary" @click="toAddHandler">添加用户</el-button>
          <el-button type="primary" @click="toAddKS">数据分析</el-button>
        </el-col>
      </el-row>
    <!-- /按钮 -->
    </div>
    <!-- {{datasetfile}} -->
  <div>
    <!-- 表格 -->
    <el-table size="small" :data="greenhouse">
    <el-table-column label="名称" prop="name" align="center"></el-table-column>
    <el-table-column
      label="状态"
      prop="status"
      align="center"
    ></el-table-column>
      <el-table-column prop="photo" align="center" label="图片" >
        <!-- 图片的显示 -->
        <template slot-scope="scope">
         <img style="width:60%" :src='"http://47.106.244.1:8888/group1/"+scope.row.photo' alt="">
          <!--<img :src="scope.row.photo" width="100" height="100" />-->
        </template>
      </el-table-column>
      <el-table-column
        label="温度"
        prop="temperature"
        align="center"
      ></el-table-column>
      <el-table-column
        label="空气湿度"
        prop="airHumidity"
        align="center"
      ></el-table-column>
      <el-table-column
        label="土壤湿度"
        prop="soilHumidity"
        align="center"
      ></el-table-column>
       <el-table-column label="时间" align="center">
            <template slot-scope="scope">
              <p>{{scope.row.createTime | fmtDate}}</p>
            </template>
        </el-table-column>  
      <!-- <el-table-column label="用户id" prop="userId" align="center"></el-table-column> -->
       <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button size="small" slot="reference"  @click="deleteHandler(scope.row)" type="text">删除</el-button>
          <el-button size="small" type="text" @click="editHandler(scope.row)">修改</el-button>
           <el-button size="small" type="text" @click="toShuiGuo">图像识别</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
  </div>
</template>
<script>
import { del, get, post} from "@/utils/request";
export default {
  // 页面数据
  data() {
    return {
       // 参数，用于保存检索的参数
      param: {},
      // 组件模板中需要的数据
      greenhouse: [],
    };
  },
  // 页面渲染的时候会调用的函数
  created() {
    this.loadGreenHouse();
  },
  // 所有的方法
  methods: {
        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url="http://39.106.31.187:8888/greenhouse/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadGreenHouse();
        });
      });
    },
    editHandler(row){
        this.$router.push({
          path:'/article/greenhouseCreate',
          query:row
        })
    },
    toAddHandler() {
      this.$router.push("/article/greenhouseCreate")
    },
    toShuiGuo() {
      this.$router.push("/image/index")
    },
    toAddKS() {
      this.$router.push("/article/KS")
    },
    loadGreenHouse() {
      let url = "http://39.106.31.187:8888/greenhouse/findAll";
      get(url, this.param).then((resp) => {
        this.greenhouse = resp.data;
      });
    },
  }
}
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
  size:"small";
}
</style>
